package com.huawei.codearts.model;


import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.math.BigDecimal;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Document(indexName = "aidite_member_demo") es索引名称为aidite_member_demo
 * todo 必须开启es服务 否则spring启动会报错
 * */
@Data
//@Document(indexName = "aidite_member_demo")  // todo 为了测试方便已关闭spring和es的关联
public class Member {
    @Id
    private int id;

    @Field(type = FieldType.Keyword, name = "user")
    private String user;

    @Field(type = FieldType.Keyword, name = "name")
    private String name;

    @Field(type = FieldType.Integer, name = "status")
    private Integer status;

    @Field(type = FieldType.Double, name = "money")
    private BigDecimal money;

    @Field(type = FieldType.Keyword, name = "statusStr")
    private String statusStr;

    @Field(type = FieldType.Long, name = "createtime")
    private Long createtime;

    @Field(type = FieldType.Date, name = "createtimeFormat", pattern = "yyyy-MM-dd HH:mm:ss")
    private String createtimeFormat;

    @Field(type = FieldType.Keyword, name = "country")
    private String country;

    @Field(type = FieldType.Keyword, name = "day")
    private String day;

//    @Field(type = FieldType.Text, name = "description", analyzer = "ik_max_word", store = true, searchAnalyzer = "ik_smart")
    @Field(type = FieldType.Text, name = "description")
    private String description;

    public Member() {}

    public Member(int id, String user, String name, int status, BigDecimal money) {
        this.id = id;
        this.user = user;
        this.name = name;
        this.status = status;
        this.money = money;
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public long getCreatetime() {
        return createtime;
    }

    public void setCreatetime(long createtime) {
        this.createtime = createtime;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getDay() {
        return day;
    }

    public String getCreatetimeFormat() {
        return createtimeFormat;
    }

    public void setCreatetimeFormat(String createtimeFormat) {
        this.createtimeFormat = createtimeFormat;
    }

    public String getStatusStr() {
        return statusStr;
    }

    public void setStatusStr(String statusStr) {
        this.statusStr = statusStr;
    }

    @Override
    public String toString() {
        return "MemberRepository{" +
                "id=" + id +
                ", user='" + user + '\'' +
                ", name='" + name + '\'' +
                ", status='" + status + '\'' +
                ", money='" + money + '\'' +
                ", statusStr='" + statusStr + '\'' +
                '}';
    }

    public static Member fromResultSet(ResultSet rs) throws SQLException {
        return new Member(
                rs.getInt("id"),
                rs.getString("user"),
                rs.getString("name"),
                rs.getInt("status"),
                rs.getBigDecimal("money")
        );
    }

}
